package org.example.java.util.concurrency.catch_exception;

import java.util.concurrent.*;

/**
 * Created by Juntao.Zhang on 2014/10/25.
 */
public class MainCannotCatchThreadException implements Runnable {
  static ExecutorService exec;
  public static void main(String[] args) {
    try {
      exec = Executors.newCachedThreadPool();
//      ExecutorService exec = new ThreadPoolExecutor(0, Integer.MAX_VALUE,
//          60L, TimeUnit.SECONDS,
//          new SynchronousQueue<Runnable>()){
//        protected void afterExecute(Runnable r, Throwable t) {
//          super.afterExecute(r, t);
//          if (t != null)
//          this.shutdown();
//        }
//      };
      exec.execute(new MainCannotCatchThreadException());
    } catch (Exception e) {
      System.err.println("exception has handled");
    }
  }

  @Override
  public void run() {
    exec.shutdown();
//    throw new RuntimeException("exception in thread");
  }
}
